home *** CD-ROM | disk | FTP | other *** search
- Path: fido.asd.sgi.com!austern
- From: anhaeupl@late.e-technik.uni-erlangen.de (Bernd Anhaeupl)
- Newsgroups: comp.std.c++
- Subject: dynamic_cast<void*>
- Date: 06 Apr 1996 11:32:28 PST
- Organization: LATE, Uni. Erlangen-Nuernberg, Germany
- Approved: austern@isolde.mti.sgi.com
- Message-ID: <4k1a4r$dim@rznews.rrze.uni-erlangen.de>
- NNTP-Posting-Host: isolde.mti.sgi.com
- X-Original-Date: 4 Apr 1996 20:06:51 GMT
- X-Auth: PGPMoose V1.1 PGP comp.std.c++
- iQBVAwUBMWbGzUy4NqrwXLNJAQEiCwIAjpATo3FqzWAnKp7KNq6CMUYZbdIo/fi/
- KGzf50WaH6qvwF2Xq0fJX6Wg2gyrApWETIcSkDkDI3mwx9Hl8mS3Fg==
- =m7Ik
- Originator: austern@isolde.mti.sgi.com
-
- Section 5.2.6 paragraph 7 of the April 95 WP states, that for
- polymorphic types, the result of a dynamic_cast<void*>(v) "is a
- pointer to the complete object (12.6.2) pointed to by v". Now
- section 12.6.2 does not define the term "complete object", which
- actually happens in section 1.4 paragraph 2, but the term
- "most derived class". This makes a differnce, if we pass a pointer
- to a data member subobject (and not a base class subobject) to
- dynamic_cast. According to 12.6.2, we would get the address of that
- data member, according to 1.4, the address of the containing
- object of that data member.
-
- Please note, that the term "complete object (12.6.2)" is also used
- in section 5.2.7, where the typeid expression is defined. Therefore
- I suppose, that in 5.2.6 and 5.2.7 "most derived object" is meant
- instead of "complete object" in both sections. Is this correct?
-
- Example:
-
- #include <typeinfo>
- #include <iostream>
-
- class foo1{
- public:
- foo1(){};
- virtual ~foo1(){}
- };
-
- class foo2{
- public:
- foo2(){};
- virtual ~foo2(){}
- };
-
- class bar:public foo1, public foo2{
- public:
- foo1 f1m;
- foo2 f2m;
- bar(){};
- virtual ~bar(){}
- };
-
- int main()
- {
- bar b;
- foo1 & f1=b;
- foo2 & f2=b;
- foo1 & f1m=b.f1m;
- foo2 & f2m=b.f2m;
-
- cout << " &b == " << &b
- << " dynamic_cast<void*>( &b) == " << dynamic_cast<void*>(&b) << endl;
- cout << " &f1 == " << &f1
- << " dynamic_cast<void*>( &f1) == " << dynamic_cast<void*>(&f1) << endl;
- cout << " &f2 == " << &f2
- << " dynamic_cast<void*>( &f2) == " << dynamic_cast<void*>(&f2) << endl;
- cout << "&f1m == " << &f1m
- << " dynamic_cast<void*>(&f1m) == " << dynamic_cast<void*>(&f1m) << endl;
- cout << "&f2m == " << &f2m
- << " dynamic_cast<void*>(&f2m) == " << dynamic_cast<void*>(&f2m) << endl;
- return 0;
- }
-
-
- Interpreting 5.2.6 in the sense of "most derived object" would yield
- something like (at least gcc 2.7.0 does it in this way)
-
- &b == 0xbffffaa8 dynamic_cast<void*>( &b) == 0xbffffaa8
- &f1 == 0xbffffaa8 dynamic_cast<void*>( &f1) == 0xbffffaa8
- &f2 == 0xbffffaac dynamic_cast<void*>( &f2) == 0xbffffaa8
- &f1m == 0xbffffab0 dynamic_cast<void*>(&f1m) == 0xbffffab0
- &f2m == 0xbffffab4 dynamic_cast<void*>(&f2m) == 0xbffffab4
-
- where "complete object" should result in
-
- &b == 0xbffffaa8 dynamic_cast<void*>( &b) == 0xbffffaa8
- &f1 == 0xbffffaa8 dynamic_cast<void*>( &f1) == 0xbffffaa8
- &f2 == 0xbffffaac dynamic_cast<void*>( &f2) == 0xbffffaa8
- &f1m == 0xbffffab0 dynamic_cast<void*>(&f1m) == 0xbffffaa8
- &f2m == 0xbffffab4 dynamic_cast<void*>(&f2m) == 0xbffffaa8
-
- --
- Bernd Anhaeupl Tel.: +49 9131 857787
- LATE - Uni Erlangen
- Cauerstr. 7 Email: anhaeupl@late.e-technik.uni-erlangen.de
- 91058 Erlangen
- ---
- [ comp.std.c++ is moderated. To submit articles: Try just posting with your
- newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
- comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
- Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
- Comments? mailto:std-c++-request@ncar.ucar.edu
- ]
-